package com.smartcat.web.actions;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.smartcat.bean.LoginUserBean;
import com.smartcat.bean.NavigateBean;
import com.smartcat.service.UserService;
import com.smartcat.web.BaseAction;

@Controller
public class LoginAction extends BaseAction{
	
	private UserService userService;
	private String username;
	private String password;
	
	private LoginUserBean userBean;
	
	
	public LoginUserBean getUserBean() {
		return userBean;
	}


	public void setUserBean(LoginUserBean userBean) {
		this.userBean = userBean;
	}




	@Autowired
	public void setUserService(UserService userService) {
		this.userService = userService;
	}


	

	public void setUsername(String username) {
		this.username = username;
	}




	public void setPassword(String password) {
		this.password = password;
	}




	@Override
	public String execute() throws Exception {
		 userBean=userService.checkLogin(username);
		if(userBean!=null){
			if(!userBean.getPassword().equals(password)){
				return ERROR;
			}else{
				List<NavigateBean> unavs=new ArrayList<NavigateBean>();
				NavigateBean nav=new NavigateBean();
				nav.setLink("www.google.com");
				nav.setShowName("google");
				unavs.add(nav);
				userBean.setUsernavs(unavs);
				getSession().put("loginUser", userBean);
			}
		}else{
			return ERROR;
		}
		return SUCCESS;
	}

}
